// index.js文件
Component({
  data: {
    active: 0,
  
    list: [
        {
          "url":"/pages/home/home",
          "text":"首页",
          "icon":"home-o",
          "info":0
        },
        {
            "url":"/pages/index/index",
            "text":"商品",
            "icon":"shop-o",
            "info":0
        },
        {
          "url":"/pages/cart/cart",
          "text":"清单车",
          "icon":"logistics",
          "info":0
      }
    ]
  },
  methods: {
    onChange(e) {
      wx.switchTab({
        url: this.data.list[e.detail].url
      });
      this.setData({
        active: e.detail
      });
    },


    init() {
      const page = getCurrentPages().pop();
      this.setData({
        active: this.data.list.findIndex(item => item.url === `/${page.route}`)
      });
    },

    setCartNumber(cartNumber) {
      let listTemp = this.data.list
      listTemp[2].info = cartNumber
      this.setData({
        list: listTemp
      })
    }
  }
});